Service.tsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. "use client";
  2. import React, {useState} from 'react'
  3. import { ServiceTypes } from "@/api/customservice";
  4. import { Link } from "@/i18n";
  5. import { useGlobalNoticeStore } from "@/stores/useGlobalNoticeStore";
  6. import { useSocialStore } from "@/stores/useSocials";
  7. import { Badge } from "antd-mobile";
  8. import { useTranslations } from "next-intl";
  9. import { FC, useEffect } from "react";
  10. import PopupHby from "@/app/[locale]/(TabBar)/(entire)/promo/PopupHby";
  11. import { redPacketApi,lredPacketApi } from "@/api/promo";
  12. import { getToken } from "@/utils/Cookies";
  13. import { getUserMoneyApi } from "@/api/user";
  14. import { useRequest } from "ahooks";
  15. interface Props {
  16. services: ServiceTypes[];
  17. socials: ServiceTypes[];
  18. }
  19. const ServiceWidget: FC<Props> = (props) => {
  20. const token = getToken();
  21. const [isShowRedPacket, setIsShowRedPacket] = useState<any>(false);
  22. const [isShowRedIcon,setIsShowRedIcon] = useState(false)
  23. const { services, socials } = props;
  24. const defaultService = services.find((item) => item.is_suspend === 1);
  25. const newServices = services.filter((item) => item.is_suspend !== 1);
  26. const setSocials = useSocialStore((state) => state.setSocials);
  27. useEffect(() => {
  28. // 数据存储,侧边栏使用
  29. setSocials(socials);
  30. }, []);
  31. const t = useTranslations("HomePage");
  32. const { unread } = useGlobalNoticeStore((state) => ({
  33. unread: state.unread,
  34. }));
  35. const getRedPacketInfo =async()=>{
  36. try{
  37. let redPacketInfo:any
  38. let actList:any = []
  39. if(token){
  40. redPacketInfo =await lredPacketApi()
  41. actList = redPacketInfo.data?.red_packets || []
  42. }else{
  43. redPacketInfo =await redPacketApi()
  44. actList = redPacketInfo.data || []
  45. }
  46. // 是否有已开始但是没领过的红包
  47. let isHasStartAct = actList.filter((aItem:any)=>{
  48. return !!aItem.is_start && !aItem.is_receive
  49. })
  50. let isShowRed = isHasStartAct.length>0
  51. setIsShowRedIcon(isShowRed)
  52. }catch(error){
  53. console.log('redPacketInfo===>error:',error)
  54. }
  55. }
  56. // 红包雨轮询
  57. useRequest(getRedPacketInfo, {
  58. pollingInterval: 180000,
  59. pollingErrorRetryCount: 1,
  60. pollingWhenHidden: false,
  61. onSuccess: (data) => {
  62. console.log('data',data)
  63. },
  64. });
  65. return (
  66. <>
  67. {/* 红包雨icon */}
  68. {
  69. isShowRedIcon && (
  70. <div
  71. className={
  72. "flex h-[0.54rem] w-[0.54rem] items-center" +
  73. " absolute bottom-[2.04rem] right-[0.12rem] z-50 justify-center cursor-pointer"
  74. }
  75. >
  76. <img
  77. className={"h-[0.3889rem] w-[0.3889rem]"}
  78. src='/hby/red-icon.png'
  79. onClick={()=>{setIsShowRedPacket(true)}}
  80. />
  81. </div>
  82. )
  83. }
  84. {/* 红包弹窗 */}
  85. {
  86. isShowRedPacket && (<PopupHby onClose={()=>{setIsShowRedPacket(false)}} />)
  87. }
  88. {defaultService && (
  89. <Link
  90. href={defaultService.url}
  91. className={
  92. "flex h-[0.54rem] w-[0.54rem] items-center justify-center rounded-[50%]" +
  93. " absolut absolute bottom-[0.84rem] right-[0.12rem] z-50 bg-gradient-to-b from-[#ff6a01] to-primary-color"
  94. }
  95. target={"_blank"}
  96. >
  97. <img
  98. className={"h-[0.3889rem] w-[0.3889rem]"}
  99. src={defaultService.icon_url}
  100. ></img>
  101. </Link>
  102. )}
  103. <Link
  104. href={"/notification"}
  105. className={
  106. "flex h-[0.54rem] w-[0.54rem] items-center" +
  107. " absolute bottom-[1.44rem] right-[0.12rem] z-50 justify-center rounded-[50%] bg-gradient-to-b from-[#0575e6] to-[#00f260]"
  108. }
  109. >
  110. <Badge content={!!unread ? unread : null} style={{ "--top": "12px" }}>
  111. <i className={"iconfont icon-duanxinguanli text-[0.3rem] text-[#fff]"}></i>
  112. </Badge>
  113. </Link>
  114. <div className={`grid grid-cols-${newServices.length >= 5 ? 5 : newServices.length}`}>
  115. {newServices.map((service, index) => {
  116. return (
  117. <Link
  118. key={index}
  119. href={service.url}
  120. target={"_blank"}
  121. className="bg-white m-[0.05rem] h-[0.3889rem] w-[0.3889rem] rounded"
  122. >
  123. <img
  124. className={"h-[0.3889rem] w-[0.3889rem]"}
  125. src={service.icon_url}
  126. ></img>
  127. </Link>
  128. );
  129. })}
  130. </div>
  131. <div className={"text-[#ff6a01]"}>{t("Service")}</div>
  132. {/*share*/}
  133. <div className={"my-[0.2rem] text-[0.08rem] text-[#adadad]"}>{t("Share")}</div>
  134. <div className={`grid grid-cols-${socials.length >= 5 ? 5 : socials.length}`}>
  135. {socials.map((service, index) => {
  136. return (
  137. <Link
  138. key={index}
  139. href={service.url}
  140. target={"_blank"}
  141. className="bg-white m-[0.05rem] h-[0.3889rem] w-[0.3889rem] rounded"
  142. >
  143. <img
  144. className={"h-[0.3889rem] w-[0.3889rem]"}
  145. src={service.icon_url}
  146. ></img>
  147. </Link>
  148. );
  149. })}
  150. </div>
  151. </>
  152. );
  153. };
  154. export default ServiceWidget;